package com.mr.security.web.commons.validate.entity;

import lombok.Data;

import java.awt.image.BufferedImage;
import java.time.LocalDateTime;

/**
 * Class: ImageCode
 * User (作者):MRui
 * TODO (描述)：验证码code
 * Date 2019-01-20 23:31
 */
@Data
public class ValidateCode {

    /** 随机数（存） */
    private String code;
    /** 过期时间 */
    private LocalDateTime expireTime;

    /** 是否过期 */
    public boolean isPeriod() {
        return LocalDateTime.now().isAfter(expireTime);
    }

    /** 构造函数1 */
    public ValidateCode(String code, LocalDateTime expireTime){
        this.code = code;
        this.expireTime = expireTime;
    }

    /** 构造函数2 传入的为秒数的时候（需要转换） */
    public ValidateCode(String code, int expireIn){
        this.code = code;
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
    }
}
